//
//  HomeViewController.m
//  Code
//
//  Created by apple on 17/10/24.
//  Copyright © 2017年 HD. All rights reserved.
//

#import "HomeViewController.h"
#import "SDCycleScrollView.h"

@interface HomeViewController ()<SDCycleScrollViewDelegate>

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.navigationController.navigationBarHidden = YES;
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)setupUI{
    self.view.backgroundColor = [UIColor whiteColor];
    //设置轮播图
    NSArray *imageNames = @[@"banner.png",
                            @"banner.png",
                            @"banner.png",
                            @"banner.png",
                            @"banner.png"
                            ];
    
    SDCycleScrollView *bannerScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, WIN_WIDTH, 180) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
    bannerScrollView.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
    bannerScrollView.pageDotImage = [UIImage imageNamed:@"pageControlDot"];
    bannerScrollView.imageURLStringsGroup = imageNames;
    [self.view addSubview:bannerScrollView];
    
    UIImageView *noticVc=[UIImageView new];
    [self.view addSubview:noticVc];
    noticVc.image=[UIImage imageNamed:@"Notice1"];
    [noticVc mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.width.equalTo(@(20));
        make.leading.equalTo(self.view.mas_leading).with.offset(20);
        make.top.equalTo(bannerScrollView.mas_bottom).with.offset(HEIGHT_INTERVAL);
    }];
    
    //设置跑马灯
    NSArray *titles = @[@"111111111111111",
                        @"222222222222222",
                        @"3333333333333333",
                        @"4444444444444444",
                        @"55555555555555555"
                        ];
    
    SDCycleScrollView *newsScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(50, bannerScrollView.frame.size.height + HEIGHT_INTERVAL, WIN_WIDTH-60, 20) delegate:self placeholderImage:nil];
    newsScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
    newsScrollView.onlyDisplayText = YES;
    newsScrollView.titlesGroup = [titles copy];
    [self.view addSubview:newsScrollView];
    //线1
    UIImageView *line1=[self createImageViewFrame:CGRectMake(0, bannerScrollView.bounds.size.height+40, WIN_WIDTH, 1) imageName:nil color:[UIColor cz_colorWithHex:0xe0e0e0]];
    [self.view addSubview:line1];
    
    //账户
    UILabel *nLabel=[UILabel new];
    [self.view addSubview:nLabel];
    nLabel.text=@"账户:";
    [nLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(40));
        make.height.equalTo(@(20));
        make.top.equalTo(noticVc.mas_bottom).with.offset(20);
        make.leading.equalTo(self.view.mas_leading).with.offset(20);
    }];
    //账号
    UILabel *nameLabel=[UILabel new];
    [self.view addSubview:nameLabel];
    nameLabel.text=@"181******2312";
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(WIN_WIDTH/2));
        make.height.equalTo(@(20));
        make.top.equalTo(newsScrollView.mas_bottom).with.offset(20);
        make.leading.equalTo(nLabel.mas_trailing).with.offset(10);
    }];
    //线2
    UIImageView *line2=[self createImageViewFrame:CGRectMake(0, bannerScrollView.bounds.size.height+80, WIN_WIDTH, 1) imageName:nil color:[UIColor cz_colorWithHex:0xe0e0e0]];
    [self.view addSubview:line2];
    //密码
    UILabel *mmLabel=[UILabel new];
    [self.view addSubview:mmLabel];
    mmLabel.text=@"000000";
    mmLabel.textAlignment=NSTextAlignmentCenter;
    mmLabel.font=[UIFont systemFontOfSize:35];
    [mmLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(66));
        make.trailing.equalTo(self.view.mas_trailing);
        make.leading.equalTo(self.view.mas_leading);
        make.top.equalTo(nLabel.mas_bottom).with.offset(61);
    }];
    //线3
//    UIImageView *line3=[self createImageViewFrame:CGRectMake(0, WIN_HEIGHT/2+WIN_HEIGHT/10, WIN_WIDTH, 1) imageName:nil color:[UIColor cz_colorWithHex:0xe0e0e0]];
//    [self.view addSubview:line3];
    //按钮
    UIButton *garbButton=[UIButton buttonWithType:(UIButtonTypeSystem)];
    [self.view addSubview:garbButton];
    garbButton.backgroundColor=[UIColor colorWithRed:0.427 green:0.843 blue:1 alpha:1];
    [garbButton addTarget:self action:@selector(achieve:) forControlEvents:UIControlEventTouchUpInside];
    [garbButton setTitle:@"获取验证码" forState:(UIControlStateNormal)];
    garbButton.layer.cornerRadius = 5.0f;
    [garbButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(30));
//        make.top.equalTo(mmLabel.mas_bottom).with.offset(50);
         make.top.equalTo(self.view.mas_bottom).with.offset(-WIN_HEIGHT/3);
        make.leading.equalTo(self.view.mas_leading).with.offset(50);
        make.trailing.equalTo(self.view.mas_trailing).with.offset(-50);
    }];
}



- (void)achieve:(id)sender {
    NSLog(@"获取验证码");
}


-(UIImageView *)createImageViewFrame:(CGRect)frame imageName:(NSString *)imageName color:(UIColor *)color
{
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:frame];
    
    if (imageName)
    {
        imageView.image=[UIImage imageNamed:imageName];
    }
    if (color)
    {
        imageView.backgroundColor=color;
    }
    
    return imageView;
}

#pragma mark - SDCycleScrollViewDelegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"---点击了第%ld张图片", (long)index);
    
    [self.navigationController pushViewController:[NSClassFromString(@"DemoVCWithXib") new] animated:YES];
}



@end
